package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.AlbumAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.AlbumUpdateDTO;
import cn.tedu.csmall.product.pojo.vo.AlbumStandardVO;
import cn.tedu.csmall.product.service.IAlbumService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@Validated
@RestController
@RequestMapping("/albums")
@Api(tags = "1. 相册管理模块")
public class AlbumController {
    @Autowired
    private IAlbumService albumService;

    // http://localhost:9080/album/add-new?name=TestAlbum001&description=TestDescription001&sort=88
    @PostMapping(value = "/add-new")
    @ApiOperation("添加相册")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid AlbumAddNewDTO albumAddNewDTO) {
        albumService.addNew(albumAddNewDTO);
        return JsonResult.ok();
    }


    // http://localhost:9080/album/delete
    @PostMapping("/{id:[0-9]}/delete")
    @ApiOperation("根据id删除相册")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "相册ID", required = true, example = "9527", dataType = "long")
    public JsonResult<Void> delete(@Range(min = 1, max = 10000, message = "删除失败，非法的ID")
                                 @PathVariable Long id) {
        log.debug("开始处理【根据Id删除数据相册】请求，参数{}",id);
        albumService.deleteById(id);
        return JsonResult.ok();
    }

    // http://localhost:8088/album/update
    @PostMapping("/update/{id:[0-9]+}")
    @ApiOperation("修改相册详情")
    @ApiOperationSupport(order = 300)
    public JsonResult<Void> update(@PathVariable Long id, AlbumUpdateDTO albumUpdateDTO) {
        log.debug("开始处理修改相册详情请求，参数id：{}，封装对象：{}",id,albumUpdateDTO);
        albumService.updateInfoById(id,albumUpdateDTO);
        return JsonResult.ok();
    }
    // http://localhost:8088/album/update
    @PostMapping("/{id:[0-9]+}")
    @ApiOperation("根据ID查询相册详情")
    @ApiOperationSupport(order = 400)
    public JsonResult<AlbumStandardVO> getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询相册详情】请求，参数id：{}",id);
        AlbumStandardVO albumStandardVO = albumService.getStandardById(id);
        return JsonResult.ok(albumStandardVO);
    }

    // http://localhost:8088/album/list
    @GetMapping("/{id:[0-9]+}/list")
    @ApiOperation("根据查看所有相册数据")
    @ApiOperationSupport(order = 500)
    public String list(@PathVariable Long id) {
        return null;
    }

}